const { ipcMain } = require("electron");
const { createWin } = require("./share");
const path = require("path");

const createSetviewWin = (parentWin) => {
    const setviewWin = createWin({
        width: 500,
        height: 400,
        modal: true,
        parent: parentWin,
        webPreferences: {
            nodeIntegration: true, // 允许预加载js文件使用require模块
            preload: path.join(__dirname, "../src/view/set/preload.js"),
        },
    }, "./src/view/set/index.html");
    return setviewWin;
};
const createIpcSet = (parentWin) => {
    let setvWin
    ipcMain.on("open-setview", () => {
        setvWin = createSetviewWin(parentWin);
        // 窗口准备好后才展示
        setvWin.once('ready-to-show', () => {
            setvWin.show()
        })

        setvWin.setAlwaysOnTop(true);

        // 监听窗口关闭
        setvWin.on('closed', () => {
            setvWin = null
        })
    });

    ipcMain.on("close-hotkeyview", () => {
        setvWin.close();
    });
}

module.exports = {
    createIpcSet
}